import { DeepSeek } from "./deepSeek";
import { BaseLLM } from "./baseLLM";
import fs from "fs";
import path from "path";

type LLMConfig = {
    name: string;
    model: string;
    apiKey: string;
    url: string;
};

export class LLMFactory {
    private static instance: LLMFactory;
    private llmMap: Map<string, BaseLLM> = new Map();

    constructor() {
        this.initializeLLMMap();
    }

    private initializeLLMMap(): void {
        try {
            const configPath = path.join(__dirname, 'llm-config.json');
            const configData = fs.readFileSync(configPath, 'utf-8');
            const configs: LLMConfig[] = JSON.parse(configData);

            for (const config of configs) {
                switch (config.name) {
                    case 'deepseek-chat':
                        this.llmMap.set(config.name, new DeepSeek(config.apiKey, config.model, config.url));
                        break;
                    // Add other LLM types here as needed
                }
            }
        } catch (error) {
            console.error('Error initializing LLM map:', error);
        }
    }

    public getLLM(modelName: string): BaseLLM | undefined {
        return this.llmMap.get(modelName);
    }
}
